package org.nox.helloseries.core.util;

import org.nox.helloseries.domain.Serie;
import org.nox.helloseries.domain.Tracker;

import com.thoughtworks.xstream.XStream;

public final class MarshallingHelper
{
    private static XStream xstream;

    private MarshallingHelper()
    {

    }

    public static Object toObject( String xml )
    {
        return getMarshaller().fromXML( xml );
    }

    public static String toXML( Object object )
    {
        return getMarshaller().toXML( object );
    }

    private static XStream getMarshaller()
    {
        if ( xstream == null )
        {
            xstream = new XStream();
            xstream.setMode( XStream.NO_REFERENCES );
            xstream.alias( "tracker", Tracker.class );
            xstream.alias( "serie", Serie.class );

            // Suppresion des champs inutiles à sauver"
            xstream.omitField( Serie.class, "nomFichier" );
            xstream.omitField( Serie.class, "seeds" );
            xstream.omitField( Serie.class, "url" );
            xstream.omitField( Serie.class, "tailleFichier" );
            xstream.omitField( Serie.class, "infos" );
            xstream.omitField( Serie.class, "serieFileInformation" );

        }
        return xstream;
    }

}
